package com.sky.service.impl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.mapper.OrdersServiceMapper;
import com.sky.result.PageResult;
import com.sky.service.OrderService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;

/**
 * @author 符健清
 * @version 1.0
 *  实现了OrderService  接口的实现类
 */
@SuppressWarnings({"all"})
@Component
public class OrderServiceimpl   implements OrderService {
    @Autowired
    private OrdersServiceMapper  ordersServiceMapper;
    /**
     * 订单分页查询
     * @param ordersPageQueryDTO
     * @return
     */
    @Override
    public PageResult pageSelectOrder(OrdersPageQueryDTO ordersPageQueryDTO) {
//       使用分页工具
//       使用pageHelper 工具分页查询
        PageHelper.startPage(ordersPageQueryDTO.getPage(),ordersPageQueryDTO.getPageSize());

//       将参数封装到 Orders 实体类  进行访问数据库
        Orders orders = new Orders();
//        使用beanutils 工具进行赋值
        BeanUtils.copyProperties(ordersPageQueryDTO, orders);
        orders.setOrderTime(ordersPageQueryDTO.getBeginTime());
        orders.setCheckoutTime(ordersPageQueryDTO.getEndTime());
        List <Orders> list  = ordersServiceMapper.pageSelectOrders(orders);

//       使用Page<Dish>强转
        Page<Orders> page = (Page<Orders>)  list ;
//       PageResult 类型封装返回
        PageResult pageResult = new PageResult();
        pageResult.setTotal(page.getTotal());
        pageResult.setRecords(page.getResult());

        return  pageResult;
    }


    /**
     *取消订单
     * @param ordersCancelDTO
     */
    @Override
    public void cancelOrder(OrdersCancelDTO ordersCancelDTO) {
         ordersServiceMapper.cancelOrder(ordersCancelDTO);
    }


    /**
     * 待接单数量
     * @return
     */
    @Override
    public Integer counToBeConfirmed() {
       Integer countToBeConfirmed= ordersServiceMapper.counToBeConfirmed();
       return countToBeConfirmed;
    }

    @Override
    public Integer countConfirmed() {
        Integer confirmed = ordersServiceMapper.confirmed();
        return confirmed;
    }


    /**
     * 派送中的数量
     * @return
     */
    @Override
    public Integer deliveryLiProgress() {
        Integer deliveryInProgress = ordersServiceMapper.deliveryInProgress();
        return deliveryInProgress;


    }


    /**
     * 完成订单
     */
    @Override
    public void finishOrder(Integer id) {
        ordersServiceMapper.finishOrder(id);
    }


    /**
     * 拒单
     * @param ordersRejectionDTO
     */
    @Override
    public void rejectionOrder(OrdersRejectionDTO ordersRejectionDTO) {
         ordersServiceMapper.rejectionOrder(ordersRejectionDTO);
    }


    /**
     * 接单
     * @param id
     */
    @Override
    public void confirmOrder(Long id) {
        ordersServiceMapper.confirmOrder(id);
    }

    /**
     *  id 查村订单
     * @param id
     */
    @Override
    public void selectOrderById(Integer id) {
        List<Orders > list  =ordersServiceMapper.selectOrdersById(id);
    }


    /**
     * 派送订单
     * @param id
     */
    @Override
    public void sendOrder(Integer id) {
         ordersServiceMapper.sendOrder(id);
    }
}
